import time
import datetime
import sys
import ipaddr

class IP(object):
	"""docstring for IP"""
	def __init__(self,*ip):
		if len(ip)==1:
			self.ip=ip[0]
			self.is_legal(self.ip)

	def __str__(self):
		return self.ip

	def __contains__(self,other):
		sip=self.str_to_ip(self.ip)
		dip=self.str_to_ip(other.ip)
		try:
			return dip in sip
		except:
			return False

	def str_to_ip(self,ip):
		try:
			return ipaddr.IPv4Address(ip)
		except:
			try:
				return ipaddr.IPv4Network(ip)
			except:
				return False

	def is_legal(self,ip):
		try:
			return ipaddr.IPv4Address(ip)
		except:
			try:
				return ipaddr.IPv4Network(ip)
			except:
				raise ValueError("Illegal %s Object"%(self.__class__.__name__))


class Port(object):
	"""docstring for Port"""
	def __init__(self, *port):
		if len(port)==1:
			self.port=port[0]
			self.is_legal(self.port)
	def __str__(self):
		return str(self.port)

	def is_legal(self,port):
		if port in range(0,65536):
			return True
		raise ValueError("Illegal %s Object"%(self.__class__.__name__))

class Time(object):
	"""docstring for Port"""
	def __init__(self, *time):
		if len(time)==1:
			self.time=time[0]

	def __str__(self):
		return str(time.mktime(datetime.datetime.strptime(self.time, "%Y-%m-%d").timetuple()))  